module.exports = (app) => {
    const { STRING, INTEGER, DATE, ENUM, TEXT } = app.Sequelize;
  
    const Branch = app.model.define("branch", {
      id: {
        type: INTEGER(20),
        primaryKey: true,
        autoIncrement: true,
      },
      name: {
        type: STRING,
        allowNull: false,
        defaultValue: "",
        comment: "学科名称",
      },
      order: {
        type: INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: "排序",
      },
      created_time: {
        type:DATE,
        get(){
           return app.formatTime(this.getDataValue('created_time'))
        }
      },
      updated_time: DATE,
    });
    Branch.associate = function(){
      // 与user表是多对多关系
      app.model.Branch.belongsToMany(app.model.User, {
          through: app.model.BranchUser,
          foreignKey: 'branch_id',
          otherKey: 'user_id'
      });
  }

  Branch.associate = function() {
    app.model.Branch.hasMany(app.model.Score, { foreignKey: 'branch_id' });
  }

  
    return Branch;
  };